package com.uidp.search;

import static com.uidp.hibernatelayer.UsergroupsDAO.GROUPNAME;
import static org.hibernate.criterion.Restrictions.eq;
import static org.apache.commons.lang.StringUtils.isNotEmpty;

import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.impl.hibernate.SearchHibernateBusinessObject;
import com.uidp.domain.Usergroups;
import com.uidp.hibernatelayer.UsergroupsDAO;
import com.uidp.hibernatelayer.UsergroupsVO;

public class UsergroupSearch extends
		SearchHibernateBusinessObject<UsergroupsVO, UsergroupsDAO, Usergroups> {

	public UsergroupSearch() throws BusinessException {
		super();

	}

	private Usergroups usergroupsCriteria;

	public UsergroupSearch(String groupname) throws BusinessException {
		this.usergroupsCriteria.setGroupname(groupname);
	}

	/** @see SearchObject#initialize() */
	@Override
	protected final void initialize() throws BusinessException {
		super.initialize();

		this.usergroupsCriteria = new Usergroups();
	}

	/** @see SearchHibernateBusinessObject#buildCriteria() */
	@Override
	protected void buildCriteria() throws SearchException {
		super.buildCriteria();
		if (isNotEmpty(getUsergroupsCriteria().getGroupname())) {
			getCriteria().add(
					eq(GROUPNAME, getUsergroupsCriteria().getGroupname()));
		}
	}

	public Usergroups getUsergroupsCriteria() {
		return usergroupsCriteria;
	}

	@Override
	protected Usergroups createResultObject(UsergroupsVO d)
			throws BusinessException {
		return new Usergroups(d);
	}

	@Override
	protected Class<UsergroupsDAO> getDAOClass() {
		return UsergroupsDAO.class;
	}

}
